package com.xbongbong.pro.service.stage.factory;

import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.pro.enums.SaasMarkEnum;
import com.xbongbong.pro.service.stage.StageFindStrategy;
import com.xbongbong.saas.enums.XbbRefTypeEnum;

import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 阶段查找工厂
 * @author zcp
 * @version v1.0
 * @since v1.0
 */
public class StageFindFactory {
    /**
     * 业务类型 - 策略类
     */
    public static final Map<Integer, StageFindStrategy> STAGE_MAP = new ConcurrentHashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);

    /**
     * 根据 businessType 获取阶段查询策略类（paas的用paas businessType即可）
     * @param businessType
     * @return com.xbongbong.pro.service.stage.StageFindStrategy
     * @author zcp
     * @since v1.0
     * @version v1.0
     */
    public static StageFindStrategy getStageFindStrategy(Integer businessType) {
        if (Objects.isNull(businessType) || Objects.equals(businessType, XbbRefTypeEnum.UNKNOWN.getCode()) || Objects.equals(businessType, XbbRefTypeEnum.CONTRACT.getCode())) {
            return STAGE_MAP.get(XbbRefTypeEnum.PAAS.getCode());
        }
        return STAGE_MAP.get(businessType);
    }
    /**
     * 根据 businessType 获取阶段查询策略类（paas的用paas businessType即可）
     * @param saasMark
     * @param businessType
     * @return com.xbongbong.pro.service.stage.StageFindStrategy
     * @author zcp
     * @since v1.0
     * @version v1.0
     */
    public static StageFindStrategy getStageFindStrategy(Integer saasMark, Integer businessType) {
        boolean flag = Objects.equals(SaasMarkEnum.PAAS.getCode(), saasMark) || Objects.isNull(businessType) || Objects.equals(businessType, XbbRefTypeEnum.UNKNOWN.getCode()) || Objects.equals(businessType, XbbRefTypeEnum.CONTRACT.getCode());
        if (flag) {
            return STAGE_MAP.get(XbbRefTypeEnum.PAAS.getCode());
        } else {
            return STAGE_MAP.get(businessType);
        }
    }
}
